function fun() {
    var mi_button = document.getElementById("mi_button");
    mi_button.setAttribute("style","background:coral");
}

function fun1() {
    var mi_button = document.getElementById("mi_button");
    mi_button.setAttribute("style","background:sandybrown");
}

var fvg1 = false;
//邮箱验证
function select1() {
    var select1 = document.getElementById("mi_select1").value;
    var email =  /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/;
    if (select1.trim().length==0){
        document.getElementById("select1").innerHTML = "邮箱不能为空！！";
    }else if ( email.test(select1)){
        fvg1 = true;
    }else {
        document.getElementById("select1").innerHTML = "邮箱格式错误！！(例如：3518485441@qq.com)";
    }
}

//随机验证码
var code = "";
function funEmail() {
    var code = "";
    var selectChars = new Array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');
    for (var i = 0; i <4 ; i++) {
        code +=selectChars[Math.floor(Math.random()*selectChars.length)];
    }
    document.getElementById("Email").style.letterSpacing="5px";//字体间距
    document.getElementById("Email").style.color="#0ab000";//字体颜色
    document.getElementById("Email").innerText = code;//显示
}

var fvg2 = false;
//获取验证码
function text() {
    var text = document.getElementById("mi_text").value;
    var auth = document.getElementById("Email").innerText;
    if (text.length == 0) {
        document.getElementById("text").innerHTML = "验证码不能为空！！";
    }else if (text == auth){
        fvg2 = true;
    }else if (text != auth){
        document.getElementById("text").innerHTML = "验证码格式错误请重新输入！！(请认真查看右侧验证码)";
    }
}

var fvg3 = false;
//密码验证
function select2() {
    var select2 = document.getElementById("mi_select2").value;
    var pass = /^[\w]{6,12}$/;
    if (select2.length == 0) {
        document.getElementById("password").innerHTML = "密码不能为空！！";
    }else if (pass.test(select2)){
        fvg3 = true;
    }else{
        document.getElementById("password").innerHTML = "密码格式错误！！(密码格式为6-12任意字符和数字)";
    }
}

var fvg4 = false;
//小米账号验证
function fun2() {
    debugger;
    var zh = document.getElementById("mi_select0").value;
    var pass = /^[\w]{6,12}$/;
    if (zh.length == 0){
        document.getElementById("select0").innerHTML = "账号不能为空！！";
    }else if (pass.test(zh)){
        fvg4 = true;
    }else {
        document.getElementById("select0").innerHTML = "账号格式错误！！（账号格式为6-12任意字符和数字）";
    }
}

function fun3() {
    document.getElementById("mi_select0").value ="";
    document.getElementById("select0").innerHTML = "";
}

function nu(textId, span) {
    document.getElementById(textId).value = "";
    document.getElementById(span).innerHTML = "";
}

function example() {
    debugger;
    var user_name = document.getElementById("mi_select0").value;
    var select1 = document.getElementById("mi_select1").value;
    var text = document.getElementById("mi_text").value;
    var select2 = document.getElementById("mi_select2").value;
    var mi_check = document.getElementById("mi_check");
    if (select1 != "" && text != "" && select2!="" && mi_check.checked == true){
        $(function () {
            $.ajax({
                url: "register?user_name="+user_name+"&password="+select2+"&Email="+select1,
                type: "get",
                dataType: "json",
                success: function (res) {
                    alert(res);
                    if (res == "注册成功！！"){
                        window.location.href = "/MyXiaomiShop/login.jsp";
                    }
                },
                error: function (res) {
                    alert("所有商品图片调用失败！")
                }
            });
        })
    }else{
        return false;
    }
}

function randomNum(min,max) {
    return Math.floor(Math.random()*(max-min)+min);
}

function email() {
    var val1 = document.getElementById("mi_text").value;
    var val2 = code;
    if (val1 != val2){
        document.getElementById("text").innerHTML = "验证码错误！！";
        document.getElementById("mi_text").value="";
    }else{
    }
}

function ema() {
    window.location.reload();
}
